package SwingController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import javax.swing.JFileChooser;

public class ALDownloadFile implements ActionListener{

	private final File srcFile;
	private JFileChooser fChooser;
	
	public ALDownloadFile(File srcFile){
		this.srcFile = srcFile;
		fChooser = new JFileChooser();
		fChooser.setCurrentDirectory(new File(System.getProperty("user.home") + File.separator + "Documents"));
		fChooser.setSelectedFile(new File(System.getProperty("user.home") + "/Documents/" + srcFile.getName()));
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		int returnVal = fChooser.showSaveDialog(null);
		
		if( returnVal == JFileChooser.APPROVE_OPTION){
			try {
				Files.copy(Paths.get(srcFile.getPath()),
							Paths.get(fChooser.getSelectedFile().getPath()), 
							StandardCopyOption.REPLACE_EXISTING);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
		}
	}
	
}
